package com.sline.day03._02_smis.template;

import com.sline.util.JdbcUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class JdbcTemplate {
    public static int update(String sql, Object ... params) {
        Connection connection = null;
        PreparedStatement preparedStatement = null;

        try {
            connection = JdbcUtil.getConnection();

            preparedStatement = connection.prepareStatement(sql);

            for (int i = 0; i < params.length; i++) {
                preparedStatement.setObject(i + 1, params[i]);
            }

            return preparedStatement.executeUpdate();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JdbcUtil.close(connection, preparedStatement, null);
        }

        return 0;
    }
}
